// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: "yipianyue2023-1-1gr6qnk7d6ba9941" }) // 使用当前云环境
function randomString() {
  let len = 32;
  let chars ='ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  let maxPos = chars.length;
  let character = '';
  for (let i = 0; i < len; i++) {
      character += chars.charAt(Math.floor(Math.random() * maxPos))
  }
  return character;
}


// 云函数入口函数
exports.main = async (event, context) => {
  console.log("来支付啦");
  const res = await cloud.cloudPay.unifiedOrder({
    "body" : "月月商城vip服务",
    "outTradeNo" : randomString(),
    "spbillCreateIp" : "127.0.0.1",
    "subMchId" : "1636932325",
    "totalFee" : 1,
    "envId": "yipianyue2023-1-1gr6qnk7d6ba9941",
    "functionName":'paycal'
  })
  console.log(res);
  return res
}

